﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Singleton<T> : MonoBehaviour where T : Component
{
    static T _instance;
    public static T Instance
    {
        get
        {
            if (_instance == null)
            {
                GameObject globel = GameObject.Find("GlobalThis");
                if (globel == null) globel = new GameObject("GlobalThis");
                DontDestroyOnLoad(globel);
                _instance = globel.GetComponent<T>();
                if (_instance == null)
                {
                    _instance = globel.AddComponent<T>();
                }
            }
            return _instance;
        }
    }
}
